
<template>
  <div class="tab-tool">
    <header>
      <div
        v-for="(item,index) in tabsArr"
        :key="index"
        :class="{'active': tabsActiveIndex==index }"
        @click="tabsHandle(index)">
        {{ item.label }}
        <span
          class="badge"
          :is-dot="true"
          v-if="item.badgeValue">
          <el-badge v-model="item.badgeValue"/>
        </span>
      </div>
    </header>
  </div>
</template>
<script>
export default {
  name: 'CustomTabs',
  data () {
    return {
      tabsActiveIndex: null
    }
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler (val) {
        this.tabsActiveIndex = val
      }
    }
  },
  props: {
    activeIndex: {
      type: Number,
      default: 0
    },
    tabsArr: {
      type: Array,
      required: true
    }
  },
  methods: {
    tabsHandle (index) {
      this.tabsActiveIndex = index
      this.$emit('returnIndex', index)
    }
  }
}
</script>
<style lang="less" scope>
  @import "../../assets/var.less";
  .tab-tool {
    background: #f7f8fa;
    padding: 0 !important;
    header {
      height: 57px;
      font-size: 14px;
      color: #909db0;
      background: #fff;
      user-select: none;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      div {
        height: 100%;
        text-align: center;
        line-height: 57px;
        padding: 0 16px;
        box-sizing: border-box;
        position: relative;
        cursor: pointer;
      }
      .badge {
        color: red;
        font-weight: normal;
        position: absolute;
        right: -16px;
        top: -6px;
      }
      div.active {
        font-size: 20px;
        color: #2371c5;
        font-weight: 500;
      }
      div.active::after {
        content: '';
        height: 2px;
        width: calc(100% - 32px);
        background: #2371c5;
        position: absolute;
        bottom: 0;
        left: 16px;
      }
    }
  }
</style>
